package com.abc.controller;

import com.abc.common.Result;
import com.abc.dto.request.AddDocumentRequestDto;
import com.abc.dto.request.SearchDocumentRequestDto;
import com.abc.dto.response.RerankResponseDto;
import com.abc.service.VectorStoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 向量存储控制器
 *
 * @author abc
 * @since 2024-01-01
 */
@Slf4j
@RestController
@RequestMapping("/api/vector")
@Tag(name = "向量存储管理", description = "向量存储相关接口")
public class VectorStoreController {

    @Autowired
    private VectorStoreService vectorStoreService;


    @PostMapping("/init")
    @Operation(summary = "初始化向量存储")
    public Result<String> initializeVectorStore() {
        vectorStoreService.initializeVectorStore();
        return Result.success("向量存储初始化成功");
    }

    @PostMapping("/add")
    @Operation(summary = "向量存储添加文档")
    public Result<String> add(@RequestBody AddDocumentRequestDto request) {
        vectorStoreService.add(request);
        return Result.success("向量存储添加文档成功");
    }

    @PostMapping("/search")
    @Operation(summary = "向量存储搜索文档")
    public Result<RerankResponseDto> search(@RequestBody SearchDocumentRequestDto request) {
        return Result.success(vectorStoreService.search(request));
    }
}

